// subpkgActivity/pages/invitationRedEnvelope/invitationRedEnvelope.ts
import {
  getInvitedSuccessfulApi,
  getInvitedRewardsApi
} from "../../../api/invite";
import {
  getToken
} from "../../../utils/storage";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isShowRecord: false,
    share_invite_key: wx.getStorageSync('invite_key'),
    currentPage: 1,
    showCount: 10,
    token: getToken(),
    list: [],
    lbList:[],
    account:0,
    backTopValue: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.getInvitedSuccessfulList()
    this.getInvitedRewardsList()
    this.computeBackTop();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },
  toBack() {
    wx.navigateBack({
      delta: 1
    })
  },
  computeBackTop() {
    const { CustomBar, StatusBar } = getApp().globalData;
    const tmpValue = (CustomBar - StatusBar - 25) / 2 + StatusBar;
    this.setData({
      backTopValue: tmpValue
    });
  },
  toInvitationRecord() {
    this.setData({
      isShowRecord: true,
    });
  },
  immediateWithdrawal() {
    wx.switchTab({
      url: '/pages/hb/hb',
    })
  },
  // 获取邀请记录列表
  getInvitedSuccessfulList() {
    getInvitedSuccessfulApi({
      token: this.data.token,
      currentPage: this.data.currentPage,
      showCount: this.data.showCount
    }).then((res) => {
      this.setData({
        list: res.data.list
      })
    })
  },
  // 获取邀请奖励列表
  getInvitedRewardsList() {
    getInvitedRewardsApi({
      token: this.data.token
    }).then((res) => {
      this.setData({
        lbList:res.data.lbList,
        account:res.data. account
      })
    })
  },
  // 立即邀请
  onShareAppMessage: function (res) {
    console.log(getApp().globalData)
    return {
      title: `${getApp().globalData.user_name}邀请你加入嗨喵大屏互动，让活动更精彩！`,
      path: `/pages/regist/regist?share_invite_key=${wx.getStorageSync('invite_key')}&user_source=5`,
      imageUrl:'https://ustatic.joymew.com/%20miao/icon/cons12.png',
    }
  },
  // 关闭邀请记录
  closeRecord() {
    this.setData({
      isShowRecord: false,
    });
  }
})